<%--
  Created by IntelliJ IDEA.
  User: 11917
  Date: 2022/7/5
  Time: 17:04
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>操作日志</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
    <script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
</head>

<body>
<form class="layui-form" action="" style="margin-top: 10px">
    <div class="layui-inline">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-inline">
            <input type="text" name="username" placeholder="用户名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label">方法名</label>
        <div class="layui-input-inline">
            <input type="text" name="methodName" placeholder="方法名" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-inline">
        <div class="layui-input-inline">
            <button class="layui-btn" lay-submit lay-filter="selectFormfilter">查询</button>
            <button type="reset" class="layui-btn layui-btn-primary" id="myButton">重置</button>
        </div>
    </div>
</form>
<table id="LogTable" lay-filter="test"></table>

<script>
    layui.use(['table', 'form', 'jquery'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;

        //第一个实例
        var myTable = table.render({
            elem: '#LogTable'
            , url: '${pageContext.request.contextPath}/log/findAllLogPage.do' //数据接口
            , page: true //开启分页
            , height: 'full-68'
            , cols: [
                [ //表头
                    {field: 'id', title: 'ID', width: 100, sort: true, fixed: 'left'}
                    , {field: 'username', title: '用户名', width: 120}
                    , {field: 'ip', title: 'ip地址', width: 120}
                    , {field: 'className', title: '类名', width: 300}
                    , {field: 'methodName', title: '方法名', width: 200}
                    , {field: 'params', title: '参数', width: 200}
                    , {field: 'createTime', title: '创建时间', width: 200,sort: true}
                ]
            ]
        });
        //====================================提交条件查询==================================================
        form.on('submit(selectFormfilter)', function (data) {
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            //提交表单数据
            /*$.ajax({
                url: "/log/selectAllPage",
                type: "POST",
                dataType: "JSON",
                data: data.field,
                success: function (ret) {
                    if (ret.code == 0) {
                        //刷新表格数据

                    } else {
                        layer.msg(ret.msg, {icon: 5});
                    }

                }
            })*/
            myTable.reload({
                where: { //设定异步数据接口的额外参数，任意设
                    username: data.field.username
                    , methodName: data.field.methodName
                }
                ,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        ///重置条件查询表单，刷新table数据
        $("#myButton").click(function () {
            myTable.reload({
                where: { //设定异步数据接口的额外参数，任意设
                    username: ""
                    , methodName: ""
                    //…
                }
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
        })

    });
</script>

</body>
</html>
